<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Layui</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="layui/css/layui.css"  media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
                      
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>Login</legend>
</fieldset>
 
<form class="layui-form" action="">
  
  <div class="layui-form-item">
    <label class="layui-form-label">账号</label>
    <div class="layui-input-inline">
      <input type="text" name="name" lay-verify="required|name" lay-reqtext="用户名是必填项，岂能为空？" placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  
  
  <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
      <input type="password" name="pwd" lay-verify="pass" placeholder="请输入密码" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">请填写6位以上密码</div>
  </div>
  

  
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form> 
<script src="layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
layui.use(['form', 'jquery'], function(){
  var form = layui.form
  ,layer = layui.layer
  ,$ = layui.$;
  
 
 
  //自定义验证规则
  form.verify({
    name:[
    /^[\S]{3,8}$/
      ,'账号必须3到8位之间，且不能出现空格'
    ]
    ,pass: [
      /^[\S]{6,}$/
      ,'密码必须6位以上，且不能出现空格'
    ]
    ,content: function(value){
      layedit.sync(editIndex);
    }
  });
  
  
  //监听提交
  form.on('submit(demo1)', function(data){
        $.ajax({
            type:"post",
            url:"Login.php",
            data:data.field,
            dataType:"json",
            success:function( res )
            {
                layer.msg( res.msg );
                if( res.code == 0 )
                {
                    location.href = "Adds.html";
                }
            }
        })

    // layer.alert(JSON.stringify(data.field), {
    //   title: '最终的提交信息'
    // })
    return false;
  });
 
});
</script>

</body>
</html>